<template>
    <div class="edit-password-container">
        <div class="edit-password-header">
            <div>
                <p style="padding: 10px 50px 10px ;text-align: left;font-weight:bold">修改密码</p>
            </div>
        </div>
        <div class="edit-password-content">
            <div>
                <el-row>
                    <el-col :span="8">
                        <el-form ref="editPasswordForm" :model="editPasswordForm" :rules="editPasswordFormRules" label-width="100px">
                            <el-form-item label="新密码" prop="password">
                                <el-input size="large" type="string" v-model="editPasswordForm.password" placeholder="新密码">
                                </el-input>
                            </el-form-item>
                            <el-form-item label="确认密码" prop="passwordCheck">
                                <el-input size="large" type="string" v-model="editPasswordForm.passwordCheck" placeholder="确认密码">
                                </el-input>
                            </el-form-item>
                            <el-form-item>
                                <el-button size="large" type="primary" @click="handleSubmit('editPasswordForm')">确认</el-button>
                                <el-button size="large" type="text" @click="handleReset('editPasswordForm')">重置</el-button>
                            </el-form-item>
                        </el-form>
                    </el-col>
                </el-row>
            </div>
        </div>
    </div>
</template>
      
<script>
// import formRules from 'mixins/formRules.js'
export default {
  // mixins: [formRules],
  data() {
    const validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        if (this.editPasswordForm.passwordCheck !== '') {
          // 对第二个密码框单独验证
          this.$refs.editPasswordForm.validateField('passwordCheck')
        }
        callback()
      }
    }
    const validatePassCheck = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.editPasswordForm.password) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
    return {
      editPasswordForm: {
        password: ''
      },
      editPasswordFormRules: {
        password: [
          { validator: validatePass, message: '请输入密码', trigger: 'blur' }
        ],
        passwordCheck: [{ validator: validatePassCheck, trigger: 'blur' }]
      }
    }
  },
  methods: {
    handleSubmit(formName) {
      this.submitForm(formName)
    },
    handleReset(formName) {
      this.resetForm(formName)
    }
  }
}
</script>
      
<style scoped>
.edit-password-container {
  margin-top: 50px;
  width: 1070px;
  height: 100%;
  float: left;
  /* text-align: left; */
  /* border: 1px solid #DCDFE6; */
  background-color: #ffffff;
}
</style>
      

